<template>
  <MyDrawer ref="myRef" title="店铺页面" @submit="submit" :disabled="false">
    <el-form :model="drawerProps.row" label-width="120" ref="formRef">
      <el-form-item label="路由名称">
        <el-input v-model="drawerProps.row.name"></el-input>
      </el-form-item>
      <el-form-item label="网址路径">
        <el-input v-model="drawerProps.row.path"></el-input>
      </el-form-item>
      <el-form-item label="小程序路径">
        <el-input v-model="drawerProps.row.app_path"></el-input>
      </el-form-item>
      <el-form-item label="路由标识">
        <el-input v-model="drawerProps.row.routeName"></el-input>
      </el-form-item>
      <el-form-item label="排序值">
        <el-input-number v-model="drawerProps.row.sort"></el-input-number>
      </el-form-item>
      <el-form-item label="head标题">
        <el-input v-model="drawerProps.row.title"></el-input>
      </el-form-item>
      <el-form-item label="head关键词">
        <el-input v-model="drawerProps.row.keywords"></el-input>
      </el-form-item>
      <el-form-item label="head描述">
        <el-input
          type="textarea"
          v-model="drawerProps.row.description"
          :input-style="{ height: '150px' }"
          :autosize="false"
        ></el-input>
      </el-form-item>
      <el-form-item label="例子">
        <el-input
          type="textarea"
          v-model="drawerProps.row.example"
          :input-style="{ height: '150px' }"
          :autosize="false"
        ></el-input>
      </el-form-item>
      <el-form-item label="参数描述">
        <el-input
          type="textarea"
          v-model="drawerProps.row.params_description"
          :input-style="{ height: '150px' }"
          :autosize="false"
        ></el-input>
      </el-form-item>

      <el-form-item label="备注">
        <div>
          <div v-pre>当前城市:{{ city }}</div>
          <div v-pre>楼盘名称:{{ loupan }}</div>
          <div v-pre>楼盘地址{{ address }}</div>
        </div>
      </el-form-item>
    </el-form>
  </MyDrawer>
</template>

<script setup lang="ts">
import MyDrawer from "@/components/MyDrawer/index.vue";
import { ElMessage, FormInstance } from "element-plus";
import { ref } from "vue";

const myRef = ref<InstanceType<typeof MyDrawer> | null>();

interface DrawerProps {
  row: any;
  api?: (params: any) => Promise<any>;
  getTable?: () => Promise<any>;
  list?: any[];
}

const initData: any = {
  id: undefined,
  name: "",
  routeName: "",
  sort: 1
};

const drawerProps = ref<DrawerProps>({ row: JSON.parse(JSON.stringify(initData)) });

const acceptParams = (params: any) => {
  drawerProps.value = params;
  myRef.value?.acceptParams();
};

const formRef = ref<FormInstance>();

const submit = () => {
  if (!formRef.value) return;
  formRef.value.validate(async valid => {
    if (!valid) return;
    await drawerProps.value.api!(drawerProps.value.row);
    ElMessage.success("成功");
    await drawerProps.value.getTable!();
    myRef.value?.close();
  });
};

defineExpose({ acceptParams });
</script>

<style></style>
